﻿CREATE proc NKNH_ImportToDB  --'30/09/2013'          
--NKNH_XuatBangExCel '2013/09/30'          
@so_ctu nvarchar(255),
@ngay_ctu datetime,
@hoten nvarchar(255),
@nosap nvarchar(255),
@tk_no nvarchar(255),
@chitiet_tkno nvarchar(255),
@no_sap nvarchar(255),
@cosap nvarchar(255),
@tk_co nvarchar(255),
@chitiet_co nvarchar(255),
@co_sap nvarchar(255),
@noi_dung nvarchar(255),
@so_tien float,
@ngoaite float,
@tien_vat float,
@nt_vat float,
@tk_vatc  nvarchar(255),
@tk_vat  nvarchar(255),
@loai_tien nvarchar(255),
@ty_gia  float        
as                   
begin                      
   -- select*from NKNH_H           
   -- select*from nknh_l  
   if exists(select * from NKNH_H Where so_ctu =@so_ctu  )  
   begin
   select ErrCode=0
   end  
   else
   begin     
    if(@tk_no in ('1121','1122'))
    begin  
                 
			insert into NKNH_H values(@so_ctu,@ngay_ctu,@nosap,@tk_no,@loai_tien,
							@chitiet_tkno,@no_sap,null,null,null,
							null,@ty_gia,null,@hoten,@noi_dung,@tk_vatc,
							@tk_vat,null,null,null,null
								) 
								
	end      
    else if(@tk_co in('1121','1122'))
    begin
    insert into NKNH_H values(@so_ctu,@ngay_ctu,null,null,@loai_tien,
							null,null,@cosap,@tk_co,@chitiet_co,
							@co_sap,@ty_gia,null,@hoten,@noi_dung,@tk_vatc,
							@tk_vat,null,null,null,null
								) 
    end
    
     select ErrCode=1           
end 
end